from django.shortcuts import render
from django.views.decorators.http import require_POST, require_http_methods

from bl.models import AccountInfo
from .models import *
# Create your views here.

@require_http_methods(['GET', 'POST'])
def sub_message(request):
    name = request.POST.get('name')
    email = request.POST.get('email')
    print(11, name, 22, email)
    address = request.POST.get('address')
    message = request.POST.get('message')
    username = request.session['username']
    user_info = AccountInfo.objects.get_one_object(username=username)
    try:
        message = Message.objects.add_message(name, email, address, message, user_info.id)
        messages = user_info.message_set.all()
    except Exception as e:
        print(str(e))
    return render(request, 'bl/liuyan.html', locals())
